package ar.com.cooker.services.util;

import ar.com.cooker.model.Dificulty;
import ar.com.cooker.model.Ingredient;
import ar.com.cooker.model.IngredientType;
import ar.com.cooker.model.Recipe;
import ar.com.cooker.model.RecipeType;
import ar.com.cooker.model.Region;
import ar.com.cooker.model.Step;
import ar.com.cooker.model.UnitType;
import ar.com.cooker.services.pojo.DificultyPojo;
import ar.com.cooker.services.pojo.IngredientPojo;
import ar.com.cooker.services.pojo.IngredientTypePojo;
import ar.com.cooker.services.pojo.RecipePojo;
import ar.com.cooker.services.pojo.RecipeTypePojo;
import ar.com.cooker.services.pojo.RegionOrigenPojo;
import ar.com.cooker.services.pojo.StepPojo;
import ar.com.cooker.services.pojo.UnitTypePojo;

public class ConvertBOtoPojo {

	public static RecipePojo getRecipePojoToRecipe(Recipe recipe){
		RecipePojo rp = new RecipePojo();
		rp.setIdRecipe(recipe.getId());
		rp.setTittle(recipe.getTittle());
		rp.setSummary(recipe.getSummary());
		rp.setCountry((recipe.getRegion()==null)?null:getRegionOrigenPojoToRegion(recipe.getRegion()));
		rp.setRecipeType((recipe.getRecipeType() == null)?null:getRecipeTypePojoToRecipeType(recipe.getRecipeType()));
		rp.setCreationDate((recipe.getCreationDate()==null)?null:recipe.getCreationDate());
		rp.setDificulty((recipe.getDificulty()==null)?null:getDificultyPojoToDificulty(recipe.getDificulty()));
		return rp;
	}
	
	public static DificultyPojo getDificultyPojoToDificulty(Dificulty dificulty){
		DificultyPojo dp = new DificultyPojo();
		dp.setIdDificulty(dificulty.getId());
		dp.setDescription(dificulty.getDescription());
		return dp;
	}
	
	public static RegionOrigenPojo getRegionOrigenPojoToRegion(Region region){
		RegionOrigenPojo rop = new RegionOrigenPojo();
		rop.setIdCountry(region.getId());
		rop.setRegion(region.getRegion());
		rop.setState(region.getCountry());
		rop.setZone(region.getContinent());
		return rop;
	}
	
	public static IngredientPojo getIngredientPojoToIngredient(Ingredient ingredient){
		
		IngredientPojo ip = new IngredientPojo();
		ip.setAmount((ingredient.getAmount() == null)?null:String.valueOf(ingredient.getAmount()));
		ip.setIdIngredient(ingredient.getId());
		ip.setIngredientType((ingredient.getIngredientType()==null)?null:getIngredientTypePojoToIngredientType(ingredient.getIngredientType()));
		ip.setUnit((ingredient.getUnitType()==null)?null:getUnitTypePojoToUnitType(ingredient.getUnitType()));
		ip.setName(ingredient.getName());
		ip.setPrice(ingredient.getPrice());
		return ip;
	}
	
	public static IngredientTypePojo getIngredientTypePojoToIngredientType(IngredientType ingredientType){
		
		IngredientTypePojo itp = new IngredientTypePojo();
		itp.setDescription(ingredientType.getDescription());
		itp.setIdIngredientType(ingredientType.getId());
		return itp;
	}
	
	public static UnitTypePojo getUnitTypePojoToUnitType(UnitType unitType){
		
		UnitTypePojo utp = new UnitTypePojo();
		utp.setIdUnit(unitType.getId());
		utp.setName(unitType.getDescription());
		return utp;
	}
	
	public static RecipeTypePojo getRecipeTypePojoToRecipeType(RecipeType recipeType){
		
		RecipeTypePojo rtp = new RecipeTypePojo();
		rtp.setIdRecipeType(recipeType.getId());
		rtp.setDescription(recipeType.getDescription());
		return rtp;
	}
	
	public static StepPojo getStepPojoToStep(Step step){
		StepPojo sp = new StepPojo();
		sp.setDetail(step.getDescription());
		sp.setIdStep(step.getId());
		sp.setOrderSteps(step.getOrder());
		sp.setTime(step.getTime());
		return sp;
	}
}
